﻿using SXFramWork.Core;
using SXFramWork.Model;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace SXFramWork.Repository
{
    public class SysJobRepository : RepositoryAbstract<SysJobEntity>, ISysJobRepository
    {
        public SysJobRepository(IDbContext dbContext) : base(dbContext)
        {

        }

        public async Task<bool> HasStop(string group, string code)
        {
            var count = await FromSql.GetStrAsync("select count(1) from sysjob where [group]=@group and code=@code and status=0");
            return count.To_Int() > 0 ? true : false;
        }

        public async Task<List<SysJobEntity>> Query(JobQueryModel model)
        {
            var sql = "select * from sysjob where 1=1 ";
            Dictionary<string, object> check = new Dictionary<string, object>();

            if (model.Name.NotNull())
            {
                check.Add("name", model.Name);
            }

            return await FromSql.GetPageListAsync(sql, model,check);
        }

        public async Task<bool> UpdateStatus(string group, string code, int status)
        {
            var count = await FromSql.ExecuteAsync("update sysjob set status=@status where [group]=@group and code=@code", new { status = status, group = group, code = code });
            return count > 1 ? true : false;
        }
    }
}
